/** @file   tempcon.c
    @author M. P. Hayes, UCECE
    @date   20 August 2007
    @brief  Main executable in the temperatur controller project
    		Simply deligates all tasks in order at a constant time interval.
*/

#include "ui.h"
#include "pacer.h"
#include "system.h"


/* Define polling rates in Hz.  */
enum {LOOP_POLL_RATE = 500};


int main (void)
{
    pacer_init (LOOP_POLL_RATE);

    ui_init (LOOP_POLL_RATE);

    system_init (LOOP_POLL_RATE);

    while (1)
    {
    	uint8_t temp_setpoint;
    	uint8_t temp_current;
    	int8_t ret;

    	pacer_wait ();

    	ui_update ();
	
    	temp_setpoint = ui_temp_setpoint_get ();

    	ret = system_update (temp_setpoint, &temp_current);

    	/* If return value is negative then there is an error.  */
    	if (ret > 0)
    		ui_temp_current_set (temp_current);
    	else if (ret < 0)
    		ui_error_set (-ret);
    }
}
